package com.he.heblog.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.he.heblog.dto.ArticleDto;
import com.he.heblog.entity.Tag;
import com.he.heblog.service.ArticleService;
import com.he.heblog.service.TagService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;
/*福利版块*/
@RequestMapping("/welfare")
@Controller
public class welfareController {

    @Autowired
    ArticleService articleService;
    @Autowired
    TagService tagService;
    @GetMapping("toPage/{page}")
    public String toQA(Model model, @PathVariable(required = false) Integer page){
        LambdaQueryWrapper<Tag> tagLambdaQueryWrapper = new LambdaQueryWrapper<>();
        tagLambdaQueryWrapper.eq(Tag::getTypeID,3);
        List<Tag> tagList = tagService.list(tagLambdaQueryWrapper);
        //        根据文章类型（forum）查询文章分页信息
        ArticleDto articleDto = new ArticleDto();
        articleDto.setArticleType(3);
        Page<ArticleDto> articleCondition = articleService.getArticleCondition(page, articleDto);
        model.addAttribute("ArticleList",articleCondition);
        model.addAttribute("tagList",tagList);
        return "front/user/welfare";
    }
    @GetMapping("toPage")
    public String toQA(Model model){
        LambdaQueryWrapper<Tag> tagLambdaQueryWrapper = new LambdaQueryWrapper<>();
        tagLambdaQueryWrapper.eq(Tag::getTypeID,3);
        List<Tag> tagList = tagService.list(tagLambdaQueryWrapper);
        //        根据文章类型（forum）查询文章分页信息
        ArticleDto articleDto = new ArticleDto();
        articleDto.setArticleType(3);
        Page<ArticleDto> articleCondition = articleService.getArticleCondition(1, articleDto);
        model.addAttribute("ArticleList",articleCondition);
        model.addAttribute("tagList",tagList);
        return "front/user/welfare";
    }
}
